<template>
  <div id="app">
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表对Vue的评论</h1>
          </div>
        </div>
      </div>
    </header>
    <div class="container">
      <CommentAdd :addComment="addComment"/>
      <CommentList :comments="comments" :delComment="delComment" />
    </div>
  </div>
</template>

<script>
import CommentAdd from './components/CommentAdd.vue'
import CommentList from './components/CommentList.vue'

export default {
  name: 'App',
  components: {
    CommentAdd,
    CommentList
  },
  data(){
    return {// 数据在哪个组件，更新数据的行为就应该定义在那个组件
    comments:[
      {
        user:'xxx',
        content:'VUE不错'
      },
      { user:'yyy', content:'VUE有点难'}
    ]
   }
  },
  methods:{
    addComment(comment){
      this.comments.unshift(comment)
    },
    delComment(index){
      this.comments.splice(index,1)
    }
  }
}
</script>

<style>


</style>
